<?php

class ValidadorDeFormularioDeAreaDeInteresse extends Model{
	
	/*******************
	 * ATRIBUTOS 
	 *******************/
	
	private $mensagemStatus;
	private $formularioValido;
	public $camposDoFormulario;
	public $errors;
	
	/*******************
	 * CONSTRUTOR 
	 *******************/
	
	public function __construct() {
		// load database library into $this->db (can be omitted if not required)
		//parent::__construct();
		$this->mensagemStatus = "";
		$this->formularioValido = false;
		$this->errors = array();
		$this->camposDoFormulario = null;
	}
	
	/*******************
	 * METODOS 
	 *******************/	

	//Verifica se há erros em qualquer um dos campos do formulário, caso houver devolve o array de erros
	public function verificarCamposValidos(){
		$this->camposDoFormulario = Validate::factory($_POST)
		->rule('areaDeInteresse', 'not_empty');


		if ($this->camposDoFormulario->check()){
			$this->setFormularioValido(true);
		}
		else{
			$this->setFormularioValido(false);			
			$this->setErros($this->camposDoFormulario->errors('camposDoFormularioDeFormularioDeAreaDeInteresse'));
			$this->redefinirMensagensDeErro();	
			echo '<br>';		
			print_r($this->getErros());
		}	
		
	}
	
	private function redefinirMensagensDeErro(){
		//REDEFININDO AS MENSAGENS DE ERRO
		if (isset($this->errors['areaDeInteresse']) || !isset($_POST['areaDeInteresse'])){
			$this->errors['areaDeInteresse'] = "Escolha uma das opções";
		}
		
		echo '<br>2';		
		print_r($this->getErros());
	}



	// This might go in base Model class
	public function getFormValues() {
		return arr::overwrite($this->fields, $this->$camposDoFormulario->as_array());
	}

	// This might go in base Model class
	public function getValidationErrors() {
		return arr::overwrite($this->fields, $this->$camposDoFormulario->errors('form_errors'));
	}


	/*	public function validadorDeFormularioDeCandidato(){

	}
	*/
	
	/*******************
	 * GETTERS/SETTERS 
	 *******************/
	
	public function isFormularioValido() {
		return $this->formularioValido;
	}
	
	public function setFormularioValido($formularioValido){
		$this->formularioValido = $formularioValido;
	}
	
	public function getErros() {
		return $this->errors;
	}
	
	public function setErros($errors){
		$this->errors = $errors;
	}
	
	public function getCamposDoFormulario() {
		return $_POST;
	}
	
	public function setCamposDoFormulario($camposDoFormulario){
		$this->camposDoFormulario = $camposDoFormulario;
	}
}
?>